import mountElement from "./mountElement";
import updateNodeElement from "./updateNodeElement";


export default function createDOMElement(vDom) {

  // console.log(vDom)
  let newElement = null;
  if (vDom.type === 'text') {
    //文本节点
    newElement = document.createTextNode(vDom.props.textContent)
  } else {
    //元素节点
    newElement = document.createElement(vDom.type);
    updateNodeElement(newElement, vDom);
  }

  newElement._vitualDOM = vDom;
  // 递归创建子节点
  vDom.props.children.forEach(child => {
    mountElement(child, newElement);
  })
  return newElement;
}
